<%--
  Created by IntelliJ IDEA.
  User: sxing
  Date: 14-10-4
  Time: 上午10:40
--%>


<%@ page contentType="text/html;charset=UTF-8" %>
<html>
<head>
    <meta name="layout" content="manage"/>
    <title>订单管理</title>
</head>

<body>
<div class="breadcrumbs" id="breadcrumbs">
    <ul class="breadcrumb">
        <li>
            <i class="icon-home home-icon"></i>
            订单管理
        </li>
        <li class="active"><g:link controller="mngAdministrator">订单管理</g:link></li>
    </ul><!-- .breadcrumb -->
    <div class="nav-search" id="nav-search">

    </div><!-- #nav-search -->
</div>
<div class="page-content">
    <div class="page-header">
        <h1>
            订单管理
            <small>
                <i class="icon-double-angle-right"></i>
                维护订单信息
            </small>
        </h1>
    </div><!-- /.page-header -->
    <div class="row">
        <div class="col-xs-12">
            <g:if test="${flash.message}">
                <div class="message alert alert-info">
                    <g:message message="${flash.message}"/>
                </div>
            </g:if>
        <!-- PAGE CONTENT BEGINS -->
            <table id="grid"></table>
            <div id="gridPager"/>
            <!-- PAGE CONTENT ENDS -->
        </div><!-- /.col -->
    </div><!-- /.row -->
</div>
<r:script>
         var listUrl = "<g:createLink controller="mngOrder" action="list" params="[format: 'json']"/>";
         var gridSelector = "#grid";
        var gridPagerSelector = "#gridPager";

        function setStatus(id,state) {
            if(confirm("确认要执行当前操作吗？")){
                var queryData={
                    "orderId":id,
                    "state":state
                };
                $("#grid").jqGrid("setGridParam", { postData: queryData }).trigger("reloadGrid");
            }
         }
        jQuery(function($) {
            $(gridSelector).jqGrid({
                caption: "订单列表",
                url: listUrl,
                 datatype: 'json',
                 colNames: [  "编码", "总价","创建时间","订单状态",'操作'],
                 colModel: [
                    {name: 'id', index: 'id',align:"center", width: 80,search: false},
                    { name: 'totalPrice', align:"right", index: 'totalPrice', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        },formatter:function(v){
                            return "￥"+v;
                        }
                    },
                    {name: 'dateCreated', index: 'dateCreated', width: 120,
                        searchoptions: {
                            sopt: ['cn']
                        },
                        formatter:function(v){
                            var str1= v.replace(/Z/, "");
                            var str2 = str1.replace(/T/, " ");
                            return (str2);
                        }
                    },
                    {name: 'orderStatus', index: 'orderStatus',align:"center", width: 120,editable:true, edittype:'text',editoptions:{value:'10:已提交;20:已付款;30:已发货;'},
                        formatter:function(v){
                            if(v==10){
                                 return"已提交";
                            }else if(v==20){
                                 return"已付款";
                            }else if(v==30){
                                 return"制作中";
                            }else if(v==40){
                                return "已发货";
                            }else if(v==50){
                                return "已收货";
                            }
                        },searchoptions: {
                            sopt: ['cn']
                        }
                    },
                    {name:'orderStatus',index:'orderStatus',width:80,align:'center',sortable:false,formatter:function(v,a,obj) {
                        var def="";
                        if(v==30){
                            def ="<a href='javascript:;' style='color:#f60' onclick='setStatus("+ obj.id +",40)' >[发货]</a>";
                        }else if(v==20){
                            def ="<a href='javascript:;' style='color:#f60' onclick='setStatus("+ obj.id +",30)' >[开始制作]</a>";
                        }
                        return def;
                    }}
                 ],
                 ondblClickRow: function(id) {
                    if (id) {
                        window.location.href="<g:createLink action='detail'/>?id=" + id;
                    }
                },
                 viewrecords: true,
                 pager: gridPagerSelector,
                 autowidth: true,
                 height: 'auto',
                 rowNum: 25,
                 recordtext: "从{0}到{1}共{2}",
                 multiselect: true,
			     multiboxonly: true,
                 jsonReader: {
                    root: 'datas',
                    page: 'page',
                    repeatitems : false
                 }
            });
            $(gridSelector).jqGrid('filterToolbar',{
                autosearch: true,
                searchOnEnter: true,
                searchOperators: true,
                stringResult:true
            });
            $(gridSelector).jqGrid('navGrid',gridPagerSelector,
                { 	//navbar options
                    add: true,
                    addicon : 'icon-plus-sign purple',
                    addfunc: function() {
                        window.location.href="<g:createLink action='create'/>";
                    },
                    edit: true,
                    del: true,
                    refreshicon : 'icon-refresh green'
                },
                { //edit
                    recreateForm: true,
                    beforeInitData: function(form) {
                        var id = $(this).jqGrid('getGridParam','selrow');
                        window.location.href="<g:createLink action='edit'/>?id=" + id;
                        return false;
                    }
                },
                { //add
                },
                {   //delete
                    url: '<g:createLink action="delete" params="[format: 'json']"/>',
                    recreateForm: true,
                    beforeShowForm: function(form, oper) {
                        form.jqFormToken({
                            tokenUrl: '<g:createLink action="resetToken"/>'
                        });
                    },
                    afterSubmit: function(response, posted) {
                        var rs = $.parseJSON(response.responseText);
                        var results = [ rs["code"] == 0, rs["message"]];
                        if (results) {
                            $(gridSelector).setGridParam({url: listUrl }).trigger("reloadGrid");
                        }
                        return results;
                    }
                }
            );
            $(gridSelector).jqGrid ('navButtonAdd', gridPagerSelector,
                { caption: ""/*"Show"*/, buttonicon: "icon-search",
                  onClickButton: function() {
                       $(gridSelector)[0].triggerToolbar();
                  }
            });
        });
</r:script>
</body>
</html>